//
//  CBaseAI.h
//  Monster_Martial_Arts_Version_0
//
//  Created by chiawei.tseng on 13/1/14.
//
//

#ifndef Monster_Martial_Arts_Version_0_CBaseAI_h
#define Monster_Martial_Arts_Version_0_CBaseAI_h

#include "CAIManager.h"
#include "AIDef.h"
#include "GameState.h"

using namespace MMA;

enum
{
    INVALID =-1,
};

//class CAIManager;
class CBattleObject;
class CAIBehavior : public IBaseState
{
public:
    
    CAIBehavior()
    {
        m_AiManager = NULL;
        m_ShouldExit = false;
    }
    
    virtual ~CAIBehavior(){}
    
    virtual bool Init(CAIManager*)=0;
    
    virtual void Entering(IStateInput*){}
    
    virtual void Update(IStateInput*){}
    
    virtual void Leaving(IStateInput*){}
    
    virtual int ShouldChange(IStateInput*)=0;//{ return AI_BEHAVIOR_INVALID_ID; }
    
    //virtual void onHandleCommand(IStateInput*){};
    
    //virtual void onHandleEvent(IStateInput*){};
    
    template<typename T>
    inline static  CAIBehavior* Create(CAIManager*);
    
protected:
    
    CAIManager*     m_AiManager;
    
    bool            m_ShouldExit;
    
    CBattleObject*  MyMaster(){return m_AiManager->GetMyMaster();}
};

template<typename T>
CAIBehavior* CAIBehavior::Create(CAIManager* ptr)
{
    CAIBehavior* pAiBehavior = new T();
    
    if (pAiBehavior && pAiBehavior->Init(ptr))
    {
        return pAiBehavior;
    }
    
    return NULL;
}

#endif
